package com.zhuss.core.processor;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.zhuss.bean.bo.food.product.stirfry.wechat.ListStirfryFetchTimeBo;
import com.zhuss.bean.unit.food.StirfryFetchTime;
import com.zhuss.core.db.dao.ext.ScheduleDao;
import com.zhuss.core.db.entity.Schedule;
import com.zhuss.enums.Area;
import com.zhuss.util.DateUtil;


/**
 * 查询schedule processor
 * @Author: zhushanshuo
 * @Date: 2020/03/13 15:51
 */
@Component("scheduleRead")
public class ScheduleRead {
	
	@Autowired
	private ScheduleDao scheduleDao;
	
	
	public List<StirfryFetchTime> listStirfryFetchTime(
			ListStirfryFetchTimeBo bo) {
		List<StirfryFetchTime> result = new ArrayList<StirfryFetchTime>();
		Date now = new Date();
		Date date = DateUtil.toDateOnly(now);
		List<Schedule> list = scheduleDao.list(date, bo.getConcurrentArea());
		transfer(list, result);
		return result;
	}
	
	private void transfer(List<Schedule> list, List<StirfryFetchTime> result) {
		if(list != null && list.size() > 0){
			for (Schedule item : list) {
				if(item.getTime() != null && item.getEnd() != null){
					StirfryFetchTime vo = new StirfryFetchTime();
					vo.setEnd(item.getEnd().getTime());
					vo.setTime(item.getTime().getTime());
					vo.setTotal(item.getTotal().longValue());
					vo.setUsed(item.getUsed().longValue());
					result.add(vo);
				}
			}
		}
	}
	
	

}
